package core

import (
	"context"
	"golang.org/x/net/ipv4"
	"nprobe/structs"
)

type Sender interface {
	GetName() string
	GetRBuf() *structs.PPRingBuffer[*SpanRecord]
	StartSender() error
	StopSender() error
}

type BaseSender struct {
	Ctx         context.Context
	Name        string
	ID          int
	DstIPs      []string
	Task        *ProbeTask
	RBuf        *structs.PPRingBuffer[*SpanRecord]
	Salts       map[int][]byte
	ReceiverCnt int

	Conn           *ipv4.RawConn
	ErrCnt         int
	CurrSpanRecord *SpanRecord
}

func (s *BaseSender) GetName() string {
	return s.Name
}

func (s *BaseSender) GetRBuf() *structs.PPRingBuffer[*SpanRecord] {
	return s.RBuf
}

func (s *BaseSender) StopSender() error {
	if s != nil {
		if s.Conn != nil {
			s.Conn.Close()
		}
	}

	return nil
}
